﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vowei.Core.Models
{
    public class DurationModel : IDuration
    {
        public string TypeName { get; set; }

        #region IDuration Members

        public DateTime? StartDate
        {
            get;
            set;
        }

        public DateTime? DueDate
        {
            get;
            set;
        }

        public TimeSpan? Duration
        {
            get
            {
                if (StartDate.HasValue && DueDate.HasValue)
                    return DueDate - StartDate;
                else
                    return null;
            }
            set
            {
                if (value == null)
                {
                    if (DueDate.HasValue)
                        DueDate = null;
                }
                else
                {
                    if (StartDate.HasValue)
                        throw new InvalidOperationException("StartDate是空值，不能在StartDate为空的情况下设置Duration属性！");

                    DueDate = StartDate + value;
                }
            }
        }

        #endregion

        #region ITable Members

        public Guid ID
        {
            get;
            set;
        }
        
        public string Title
        {
            get;
            set;
        }

        #endregion

        #region INestedSet Members

        public int Lower
        {
            get;
            set;
        }

        public int Upper
        {
            get;
            set; 
        }

        #endregion
    }
}
